Skip to content

Adding ScrollingLabel #164

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 9, 2022
Merged

Adding ScrollingLabel #164

merged 4 commits into from
Feb 9, 2022

Conversation

FoamyGuy
Copy link
Contributor

@FoamyGuy FoamyGuy commented Feb 8, 2022

This adds a new ScrollingLabel that is a fixed-width label that can scroll the text leftward like a marquee.

An example has been provided to show the most basic usage.

This component is used in my PyPortal Winamp player project but I figured this piece is generic enough to re-used for other purposes.

@kmatch98
Copy link
Contributor

kmatch98 commented Feb 8, 2022

  • I verified that label_direction works as expected giving different rotation options.
  • I verified that background_color works. On proportional fonts, the right side of the label gets resized as it scrolls, that's just a consequence of the backside bounding box changing sizes. That could be an area for future improvement.
  • Redefining full_text works too.

One item for consideration:

The keyword argument full_text had to be used so that you wouldn't conflict with the existing superclass .text property. And I see you put a warning, but it seems a little harder to use that way.

Perhaps making the this a subclass Group (that contains your Label) would give you the flexibility to use an input parameter named text. This will make its external definition more similar to Label and then easier to convert between Label and ScrollingLabel.

@FoamyGuy
Copy link
Contributor Author

FoamyGuy commented Feb 8, 2022

Thanks for taking a look. I do like this idea better to use text instead of full_text and switch the parent class to allow for it. I'll make that change tonight and add a new commit with it.

@FoamyGuy
Copy link
Contributor Author

FoamyGuy commented Feb 9, 2022

After tinkering with it for a bit I'm interested to see if there is a way to do this without having to extend Group instead of Label. If we change the super class it means we would lose all of the "pass through" properties so for setting things like color or background_color get tricky.

Something like this would no longer work:

my_scrolling_label.color = 0x00ff00

we could add "boilerplate" properties that copy all of the Label ones and pass them through to the Label instance but I wonder if there is some way we can avoid needing all of the extra code to re-declare each property.

I have changed the argument name to text instead of full_text and removed the warning. All of this does work as-is. But it does kind of leave open the issue that user might get unexpected results if they are changing the text after the fact trying to do something like:

my_scrolling_label.text = "the new text long enough to scroll"

@kmatch98
Copy link
Contributor

kmatch98 commented Feb 9, 2022

Thanks for the comments about using Label versus Group, and it makes sense. It's awkward to initialize with text input parameter and then full_text as a getter/setter but I understand the limit. I remember previously trying to overriding Group's superclass instance variables versus subclass variables and hit one of the limits of CircuitPython (I think it was with scaling).

Oh, and thanks for catching the example code update.

I think this is ok for now, so I'll merge it.

@kmatch98 kmatch98 merged commit 0fa39f1 into adafruit:main Feb 9, 2022
adafruit-adabot added a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request Feb 11, 2022
Updating https://github.com/adafruit/Adafruit_CircuitPython_AS7341 to 1.2.3 from 1.2.2:
  > Consolidate Documentation sections of README
  > Merge pull request adafruit/Adafruit_CircuitPython_AS7341#22 from Neradoc/patch-1

Updating https://github.com/adafruit/Adafruit_CircuitPython_VCNL4010 to 0.11.0 from 0.10.10:
  > Consolidate Documentation sections of README
  > Merge pull request adafruit/Adafruit_CircuitPython_VCNL4010#22 from stonehippo/proximity_frequency_read_fix

Updating https://github.com/adafruit/Adafruit_CircuitPython_BLE_BroadcastNet to 0.12.0 from 0.11.1:
  > Consolidate Documentation sections of README
  > Merge pull request adafruit/Adafruit_CircuitPython_BLE_BroadcastNet#27 from tekktrik/feature/use-ble-consts

Updating https://github.com/adafruit/Adafruit_CircuitPython_BLE_Adafruit to 1.4.0 from 1.3.3:
  > Consolidate Documentation sections of README
  > Merge pull request adafruit/Adafruit_CircuitPython_BLE_Adafruit#19 from tekktrik/feature/use-ble-consts

Updating https://github.com/adafruit/Adafruit_CircuitPython_BLE_LYWSD03MMC to 1.0.5 from 1.0.4:
  > Consolidate Documentation sections of README
  > Merge pull request adafruit/Adafruit_CircuitPython_BLE_LYWSD03MMC#4 from tekktrik/doc/add-typing

Updating https://github.com/adafruit/Adafruit_CircuitPython_BusDevice to 5.1.3 from 5.1.2:
  > Merge pull request adafruit/Adafruit_CircuitPython_BusDevice#76 from tekktrik/doc/consolidate-readme
  > Merge pull request adafruit/Adafruit_CircuitPython_BusDevice#75 from tekktrik/doc/add-typing

Updating https://github.com/adafruit/Adafruit_CircuitPython_Display_Text to 2.22.0 from 2.21.4:
  > Post-patch cleanup
  > Consolidate Documentation sections of README
  > Merge pull request adafruit/Adafruit_CircuitPython_Display_Text#164 from FoamyGuy/scrolling_label

Updating https://github.com/adafruit/Adafruit_CircuitPython_MagTag to 2.1.7 from 2.1.6:
  > Consolidate Documentation sections of README
  > Merge pull request adafruit/Adafruit_CircuitPython_MagTag#78 from VPTechOps/VPTechOps
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants